﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using DLV.Utilities;
using DLV.Library.Utilities;

namespace DLV.Data.Entities
{
    public class TypeController
    {
        public int InsertType(TypeInfo info)
        {
            return SQL.InsertType(info.TypeName, info.TypeOf, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void UpdateType(TypeInfo info)
        {
            SQL.UpdateType(info.TypeId, info.TypeName, info.TypeOf, info.CreatedBy, info.CreatedDate, info.UpdatedBy, info.UpdatedDate, info.Status);
        }
        public void DeleteType(TypeInfo info)
        {
            DeleteType(info.TypeId);
        }
        public void DeleteType(int typeId)
        {
            SQL.DeleteType(typeId);
        }
        public TypeInfo GetType(int typeId)
        {
            return CBO.FillObject<TypeInfo>(SQL.GetType(typeId));
        }
        public List<TypeInfo> ListType()
        {
            return CBO.FillCollection<TypeInfo>(SQL.ListType());
        }
        public List<TypeInfo> ListTypeByTypeOf(int type)
        {
            return ListType().Where(p => p.TypeOf == type).ToList();
        }
        public DataTable SelectType()
        {
            return CBO.ConvertToDataTable(ListType(), typeof(TypeInfo));
        }

        public Dictionary<object, object> ListTypeLookup()
        {
            var users = ListType().Where(p=>p.Status==(int)Globals.DocumentStatus.Use).OrderBy(p=>p.TypeName);
            var dicusers = new Dictionary<object, object>();
            foreach (TypeInfo info in users)
                dicusers.Add(info.TypeId, info.TypeName);
            return dicusers;
        }
        
    }
}
